package com.example.demo.Controller1;

import com.example.demo.mapper.UserInfoXmlMapper;
import com.example.demo.mapper.UserinfoDao;

import com.example.demo.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("/test01")
public class UserinfoController {

        @Autowired
        public UserinfoDao userInfoDao;

        @Autowired
        public UserInfoXmlMapper mapper;
        @RequestMapping("/01")
        public List<UserInfo> selectUserInfo(){
            List<UserInfo> list = userInfoDao.selectAll();
            System.out.println(list.toString());
            System.out.println("1122");
            return list;
        }
        @RequestMapping("/test11")
        public String fun1(){
            System.out.println("111");
            return "dada";
        }
        @RequestMapping("02")
    public UserInfo selectOneUserInfo(Integer id){
           UserInfo userInfo =  userInfoDao.selectOne(id);
            System.out.println(userInfo);
           return  userInfo;
        }

        @RequestMapping("03")
    public List<UserInfo> selectAll2(){
            List<UserInfo> list = mapper.selectAll();
            System.out.println(list);
            return list;
        }

        @RequestMapping("04")
    public void insertTest(){
            UserInfo userInfo = new UserInfo();
            userInfo.setUsername("niu");
            userInfo.setPassword("123");
            userInfo.setAge(1);
            userInfo.setGender(2);
            userInfo.setPhone("123344");
            userInfoDao.insert(userInfo);
            System.out.println(userInfoDao.selectAll());
        }

@RequestMapping("05")
    public void deleteUserInfo(Integer id){
            userInfoDao.delete(id);
    System.out.println(userInfoDao.selectAll());
}

@RequestMapping("06")
    public void updateUserInfo(){
            UserInfo userInfo = new UserInfo();
           userInfo.setUsername("wffu");
            userInfo.setPassword("123");
            userInfo.setId(6);
            userInfo.setAge(1);
            userInfo.setGender(2);
            userInfoDao.update(userInfo);
}


}
